import { ApiProperty } from '@nestjs/swagger';
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { Order } from './order.entity';

@Entity()
export class User {
  @ApiProperty({ description: '用户ID', example: 1 })
  @PrimaryGeneratedColumn()
  userId: number;

  @ApiProperty({ description: '用户名', example: 'zhangsan' })
  @Column()
  username: string;

  @ApiProperty({ description: '密码', example: 'password123' })
  @Column({
    // select: false,
  })
  password: string;

  @ApiProperty({ description: '邮箱地址', example: 'user@example.com' })
  @Column()
  email: string;

  @ApiProperty({
    description: '用户类型: 1=管理员, 2=普通用户',
    example: 2,
    default: 2,
  })
  @Column({ default: 2 })
  isAdmin: number; // 1表示管理员，2表示普通用户

  @ApiProperty({ description: '用户的所有订单', type: () => [Order] })
  @OneToMany(() => Order, (order) => order.user)
  orders: Order[];
}
